package com.wx.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wx.entity.WechatUser;
import com.wx.entity.WechatUserAmount;
import com.wx.entity.WechatUserSession;
import com.wx.mapper.WechatUserAmountMapper;
import com.wx.mapper.WechatUserMapper;
import com.wx.mapper.WechatUserSessionMapper;
import com.wx.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private WechatUserMapper userMapper;
	
	@Autowired
	private WechatUserMapper wechatUserMapper;
	
	@Autowired
	private WechatUserSessionMapper wechatUserSessionMapper;
	
	@Autowired
	private WechatUserAmountMapper wechatUserAmountMapper;
	
	@Override
	public WechatUser selectById(Integer id) {
		return wechatUserMapper.selectByPrimaryKey(id);
	}

	@Override
	public int insert(WechatUser user) {
		return wechatUserMapper.insert(user);
	}

	@Override
	public void updateById(WechatUser user) {
		userMapper.updateByPrimaryKey(user);
	}

	@Override
	public WechatUserSession findByOpenid(String openid) {
		return wechatUserSessionMapper.findByOpenid(openid);
	}

	@Override
	public void updateLogin(Integer id, String dateLogin, String ipLogin) {
		wechatUserMapper.updateLogin(id, dateLogin, ipLogin);
	}

	@Override
	public void insertUserSession(WechatUserSession session) {
		wechatUserSessionMapper.insert(session);
	}

	@Override
	public void updateToken(Integer uid, String token) {
		wechatUserSessionMapper.updateToken(uid, token);
	}

	@Override
	public Integer selectUidByToken(String token) {
		return wechatUserSessionMapper.selectUidByToken(token);
	}

	@Override
	public WechatUserAmount selectAmountByUid(Integer uid) {
		return wechatUserAmountMapper.selectByUid(uid);
	}

	@Override
	public void insertUserAmount(WechatUserAmount amount) {
		wechatUserAmountMapper.insert(amount);
	}

}
